package com.neidetcher.tuml;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;

import com.neidetcher.tuml.model.Model;

public class Main
{
   public static void main(String[] args)
   {
      String fileName = args[0];
      run(fileName);
   }
   
   public static void run(String fileName)
   {
      List<String> lines = fileToStrings(fileName);
      Model model = Parser.parse(lines);
      RenderEngine renderEngine = new SequenceDiagramSvgRenderEngine();
      renderEngine.setFileNamePrefix("target/integration-test-out");
      renderEngine.setModel(model);
      try
      {
         renderEngine.render(800, 500);
      } catch (Exception e)
      {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
   }

   public static List<String> fileToStrings(String fileName)
   {
      List<String> lines = new ArrayList<String>();

      try
      {
         File file = new File(fileName);
         FileReader fr = new FileReader(file);
         BufferedReader in = new BufferedReader(fr);
         String line;
         while ((line = in.readLine()) != null)
         {
            System.out.println(line);
            lines.add(line);
         }

      } catch (Exception e)
      {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }

      return lines;
   }

}
